<? 

//include "Snoopy.class.php";

$last_tag = "";

class rss_feed{
	
	var $title = array();
	var $description = array();
	var $link = array();
	var $date = array(array(), array());
	var $snoopy;
	var $data;
	var $rss_url;
	var $xml_parser_handle;
	var $last_data;
	var $item_passed;
	var $feed_data = array();
	var $item_data;
	var $counter=0;

	function rss_feed($url){
	
		$this->rss_url = $url;
		$this->dcmi_object = "";
		
	}
	
	function get_feed(){
			
		$this->xpert_xml_object_create();
				
	}
	
	function xpert_start_tag(&$parser, $name, $attribs){
	
		$name = strtoupper($name);
								
		if($name=="RDF:RDF"){
		
			$this->feed_type="RDF";
					
		}else{
		
			$this->feed_type="RSS";
		
		}
			
		if($name=="ITEM"){
						
			$this->item_passed=true;
		
		}else if($name=="ENCLOSURE"){
		
			$this->enclosure=true;
			
			$this->enclosure_data=$attribs[URL];
				
		}

	}
	
	function xpert_end_tag(&$parser, $name){
	
		$name = strtoupper($name);
				
		$this->last_data = ltrim($this->last_data);
		
		if($this->item_passed){
				
			if($this->last_data!=""){
			
				if($name!="ITEM"){
														
					if(!isset($this->dcmi_object->{$name})){
					
						$this->dcmi_object->{$name} = array();	
						
					}					
				
					if($name=="DC:FORMAT"&&$this->xerte){
					
						array_push($this->dcmi_object->{$name},"Xerte Online Toolkits");										
					
					}
						
					array_push($this->dcmi_object->{$name},$this->last_data);					
												
				}
		
			}
			
			if($name=="ITEM"){
			
				$this->feed_data[$this->counter++] = $this->dcmi_object;
									
				$this->dcmi_object = "";
				
				$this->item_data = array();
				
				$this->item_passed = false;
											
			}
			
		}else{
		
			if($name=="GENERATOR"){
	
				if($this->last_data=="Xerte Online Toolkits"){
				
					$this->xerte = true;
					
				}				
				
			}
		
		}
		
		if($this->last_data!=""){
			
		}

		$this->last_data = "";
		
	}
	
	function data_clean_up($xml_data){
	
	
		return $xml_data;
	
	}
	
	function xpert_node_contents(&$parser , $xml_data){

		$this->last_data .= $xml_data;
		
	}
	
	function xpert_xml_object_create(){
	
		$this->xml_parser_handle = xml_parser_create("utf-8");
		
		xml_set_object($this->xml_parser_handle, $this);
		
		xml_parser_set_option($this->xml_parser_handle, XML_OPTION_SKIP_WHITE, 1);
		
		if(xml_set_element_handler($this->xml_parser_handle,"xpert_start_tag","xpert_end_tag")){

			if(xml_set_character_data_handler($this->xml_parser_handle, "xpert_node_contents")){
						
				$this->xml_result = xml_parse($this->xml_parser_handle, $this->data);
				
			}else{

			}
	
	    }else{
		
		}
	
	}

}


?>